package com.jingan.nursinghome.regulatory.view;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;

import cn.android.support.v7.lib.sin.crown.base.BaseView;
import cn.android.support.v7.lib.sin.crown.utils.AssetsUtils;
import cn.android.support.v7.lib.sin.crown.utils.ProportionUtils;

/**
 * Created by 彭治铭 on 2017/9/30.
 */

public class SpannerView extends BaseView {
    public SpannerView(Context context) {
        super(context);
        init();
    }

    public SpannerView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    int strokeWidth = ProportionUtils.getInstance().adapterInt(6);
    int strockeColor = Color.parseColor("#C9C9C9");
    int mianTextColor = Color.BLACK;
    int subTextColor = Color.parseColor("#999999");
    int textSize = ProportionUtils.getInstance().adapterInt(30);
    int textBackground = Color.parseColor("#E9EEF2");
    int rightWdith = ProportionUtils.getInstance().adapterInt(62);
    int rightBackground = Color.WHITE;
    Bitmap rightBitmap;
    String info = "";

    //设置信息
    public void setInfo(String info) {
        this.info = info;
        invalidate();
    }

    boolean isscore=false;//是否已经打分

    public void setIsscore(boolean isscore) {
        this.isscore = isscore;
    }

    public void setInfoAndColor(String info, int color) {
        this.info = info;
        textPaint.setColor(color);
        invalidate();
    }

    public String getInfo() {
        return info;
    }

    public void setTextSize(int textSize) {
        this.textSize = textSize;
        invalidate();
    }

    private void init() {
        rightBitmap = AssetsUtils.getInstance().getBitmapFromAssets( "图标/下方向键.png", 0, true);
        rightBitmap = ProportionUtils.getInstance().adapterBitmap(rightBitmap);
        textPaint.setTextAlign(Paint.Align.LEFT);
        textPaint.setColor(subTextColor);
        textPaint.setTextSize(textSize);
    }

    @Override
    public void draw(Canvas canvas) {
        super.draw(canvas);
        //画背景
        if(isscore){
            canvas.drawColor(Color.parseColor("#4B97F0"));
        }else {
            canvas.drawColor(textBackground);
        }
        //画边框
        paint.setColor(strockeColor);
        paint.setStrokeWidth(strokeWidth);
        paint.setStyle(Paint.Style.STROKE);
        canvas.drawRect(0, 0, getWidth(), getHeight(), paint);
        //設置信息
        canvas.drawText(info, (float) (textSize*0.6), (getHeight() - textSize) / 2 + textSize, textPaint);
        //画右边
        paint.setStyle(Paint.Style.FILL_AND_STROKE);
        paint.setColor(rightBackground);
        paint.setStrokeWidth(0);
        int right = getWidth() - rightWdith;
        canvas.drawRect(right, 0+strokeWidth/2, getWidth()-strokeWidth/2, getHeight()-strokeWidth/2, paint);
        canvas.drawBitmap(rightBitmap, right + (getWidth() - right - rightBitmap.getWidth()) / 2, (getHeight() - rightBitmap.getHeight()) / 2, paint);
    }
}
